package com.wgchao.amc.mapstruct.mapper.expand;

import com.wgchao.amc.entity.autho.SysAuthoRole;
import com.wgchao.amc.entity.autho.SysAuthoRoleFunc;
import com.wgchao.amc.mapstruct.DTOMapper;
import com.wgchao.amc.mapstruct.dto.SysAuthoRoleDTO;
import com.wgchao.amc.mapstruct.mapper.SysAuthoRoleFuncMapper;
import com.wgchao.amc.mapstruct.mapper.SysAuthoRoleMapper;
import com.wgchao.amc.repository.autho.SysAuthoRoleFuncRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName: SysAuthoRoleMapperExpand
 * @author: wgchao
 * @createTime: 2019/10/31 10:15 AM
 * @Description: TODO
 */
@Component
public class SysAuthoRoleMapperExpand implements DTOMapper<SysAuthoRole, SysAuthoRoleDTO> {
    @Autowired
    private SysAuthoRoleMapper authoRoleMapper;
    @Autowired
    private SysAuthoRoleFuncRepository authoRoleFuncRepository;
    @Autowired
    private SysAuthoRoleFuncMapper authoRoleFuncMapper;

    @Override
    public SysAuthoRole toEntity(SysAuthoRoleDTO sysAuthoRoleDTO) {
        return authoRoleMapper.toEntity(sysAuthoRoleDTO);
    }

    @Override
    public SysAuthoRoleDTO toDTO(SysAuthoRole sysAuthoRole) {
        return authoRoleMapper.toDTO(sysAuthoRole);
    }

    @Override
    public List<SysAuthoRole> toEntity(List<SysAuthoRoleDTO> sysAuthoRoleDTOS) {
        return authoRoleMapper.toEntity(sysAuthoRoleDTOS);
    }

    @Override
    public List<SysAuthoRoleDTO> toDTO(List<SysAuthoRole> sysAuthoRoles) {
        return authoRoleMapper.toDTO(sysAuthoRoles);
    }

    public SysAuthoRoleDTO getFuncInfo(SysAuthoRoleDTO authoRoleDTO){
        List<SysAuthoRoleFunc> authoRoleFuncs = authoRoleFuncRepository.findAllByArId(authoRoleDTO.getId());
        if(authoRoleFuncs!=null && !authoRoleFuncs.isEmpty()){
            authoRoleDTO.setFuncInfos(authoRoleFuncMapper.toDTO(authoRoleFuncs));
        }
        return authoRoleDTO;
    }
}
